﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Utilities;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Converters;
using GroupCheer.FBGraphAPI.Core;

namespace GroupCheer.FBGraphAPI.API
{
    public class Info
    {       
        public static Dictionary<string, string> GetProfile()
        {
            string jsonResponse = Network.MakeHttpGet("https://graph.facebook.com/me?access_token=" + FBGraphAPIConfiguration.FBValidAccessToken);
            Dictionary<string, string> results = new Dictionary<string, string>();
            JObject jsonObject = JObject.Parse(jsonResponse);

            if (jsonObject.Properties().Count() > 0)
            {
                results.Add("id", (jsonObject.SelectToken("id", false) as JValue).Value.ToString());
                results.Add("name", (jsonObject.SelectToken("name", false) as JValue).Value.ToString());
                results.Add("email", (jsonObject.SelectToken("email", false) as JValue).Value.ToString());
                results.Add("link", (jsonObject.SelectToken("link", false) as JValue).Value.ToString());
            }

            return results;
        }
    }
}
